<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge"/>
    <title>在线购物网站~</title>
    <!--确定页面资源使用一个固定的参考路径-->
    <base href="<%=request.getContextPath()+"/"%>">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
    <link rel="stylesheet" href="assets/css/vendor/vendor.min.css"/>
    <link rel="stylesheet" href="assets/css/plugins/plugins.min.css"/>
    <link rel="stylesheet" href="assets/css/style.min.css"/>
    <script src="script/jquery-3.6.0.min.js"></script>
    <script type="text/javascript">
        $(function () {

            //账号异步请求是否存在
            $("#username").blur(function () {
                var username = this.value;
                $.getJSON(
                    "MemberServlet",
                    {
                        "action": "isExistUserName",
                        "username": username,
                        data: new Date()
                    },
                    function (data){

                        if(data.isExist){
                            $("span.errorMsg").text("用户名已存在");
                        }else{
                            $("span.errorMsg").text("用户名可用");
                        }
                    }
                )
            })

            //验证码异步请求是否相同
            $("#code").blur(function () {
                var code = this.value;
                $.getJSON(
                    "MemberServlet",
                    {
                        "action": "isTrueCode",
                        "code": code,
                        data: new Date()
                    },
                    function (data){
                        console.log(data.isTrue)

                        if(data.isTrue){
                            $("span.errorMsgCode").text("验证码正确");
                        }else{
                            $("span.errorMsgCode").text("验证码错误");
                        }
                    }
                )
            })


            //账号检验
            $("#sub-btn").click(function () {
                var usernameVal = $("#username").val();
                var usernamePattern = /^\w{6,10}$/;
                if (!usernamePattern.test(usernameVal)) {
                    $("span.errorMsg").text("账号格式不对,需要6-10个字符");
                    return false;
                }
                //密码检验
                var passwordVal = $("#password").val();
                var passwordPattern = /^\w{6,10}$/;
                if (!passwordPattern.test(passwordVal)) {
                    $("span.errorMsg").text("密码格式不对,需要6-10个字符");
                    return false;
                }
                //两次密码相同检验
                var repwdVal = $("#repwd").val();
                if (repwdVal != passwordVal) {
                    $("span.errorMsg").text("输入两次密码不相同");
                    return false;
                }
                //邮箱检验
                var emailVal = $("#email").val();
                var emailPattern = /^[\w-]+@([a-zA-Z]+\.)+[a-zA-Z]+$/;
                if (!emailPattern.test(emailVal)) {
                    $("span.errorMsg").text("电子邮件格式不对");
                    return false;
                }
                //验证码：浏览器验证不能为空
                var codeText = $("#code").val();
                //去掉验证码前后空格
                codeText = $.trim(codeText);
                if (codeText == null || codeText == "") {
                    //提示
                    $("span.errorMsg").text("验证码不能为空！");
                    return false;
                }
                $("span.errorMsg").text("验证通过");
                return true;

            })
            //对验证码进行点击刷新
            $("#codeImg").click(function () {
                //浏览器在url没有变化的时候，图片不会发出新的请求
                this.src = "<%=request.getContextPath()+"/"%>KaptchaServlet?d=" + new Date();
            })

            //决定是显示登录还是注册，默认登录，注册失败回显注册界面
            if ("${requestScope.active}" == "register") {
                $("#register_tab")[0].click();
            }


        })
    </script>
</head>

<body>
<!-- Header Area start  -->
<div class="header section">
    <!-- Header Top Message Start -->
    <!-- Header Top  End -->
    <!-- Header Bottom  Start -->
    <div class="header-bottom d-none d-lg-block">
        <div class="container position-relative">
            <div class="row align-self-center">
                <!-- Header Logo Start -->
                <div class="col-auto align-self-center">
                    <div class="header-logo">
                        <a href="index.jsp"><img src="assets/images/logo/logo.png" title="返回首页" alt="Site Logo"/></a>
                    </div>
                </div>
                <!-- Header Logo End -->

            </div>
        </div>
    </div>
    <!-- Header Bottom  Start 手机端的header -->
    <div class="header-bottom d-lg-none sticky-nav bg-white">
        <div class="container position-relative">
            <div class="row align-self-center">
                <!-- Header Logo Start -->
                <div class="col-auto align-self-center">
                    <div class="header-logo">
                        <a href="index.html"><img width="280px" src="assets/images/logo/logo.png"
                                                  alt="Site Logo"/></a>
                    </div>
                </div>
                <!-- Header Logo End -->
            </div>
        </div>
    </div>
    <!-- Main Menu Start -->
    <div style="width: 100%;height: 50px;background-color: black"></div>
    <!-- Main Menu End -->
</div>
<!-- Header Area End  -->
<!-- login area start -->
<div class="login-register-area pt-70px pb-100px">
    <div class="container">
        <div class="row">
            <div class="col-lg-7 col-md-12 ml-auto mr-auto">
                <div class="login-register-wrapper">
                    <div class="login-register-tab-list nav">
                        <a class="active" data-bs-toggle="tab" href="#lg1">
                            <h4>会员登录</h4>
                        </a>
                        <a id="register_tab" data-bs-toggle="tab" href="#lg2">
                            <h4>会员注册</h4>
                        </a>
                    </div>
                    <div class="tab-content">
                        <div id="lg1" class="tab-pane active">
                            <div class="login-form-container">
                                <div class="login-register-form">
                                    <%-- 提示错误信息--%>
                                    <span style="font-size:18pt;font-weight:bold;float:right;color: gainsboro ">
                                        ${requestScope.msg}
                                    </span>

                                    <form action="MemberServlet" method="post">
                                        <%--                                        增加隐藏域--%>
                                        <input type="hidden" name="action" value="login">
                                        <input type="text" name="user-name" value="${requestScope.username}"
                                               placeholder="Username"/>
                                        <input type="password" name="user-password" placeholder="Password"/>
                                        <div class="button-box">
                                            <button type="submit"><span>Login</span></button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                        <div id="lg2" class="tab-pane">
                            <div class="login-form-container">
                                <div class="login-register-form">
                                    <span class="errorMsg"
                                          style="float: right; font-weight: bold; font-size: 20pt; margin-left: 10px;">
                                        ${requestScope.msg}
                                    </span>
                                    <form action="MemberServlet" method="post">
                                        <input type="hidden" name="action" value="register">
                                        <input type="text" id="username" name="username"
                                               value="${requestScope.username}" placeholder="Username"/>
                                        <input type="password" id="password" name="password"
                                               value="${requestScope.password}" placeholder="输入密码"/>
                                        <input type="password" id="repwd" name="repassword"
                                               value="${requestScope.password}" placeholder="确认密码"/>
                                        <input name="email" id="email" placeholder="电子邮件" value="${requestScope.email}"
                                               type="email"/>
                                        <input type="text" id="code" name="code" style="width: 50%"
                                               placeholder="验证码"/>　　<img id="codeImg" alt="" src="KaptchaServlet"
                                                                         style="width: 120px;height:50px">
                                        <span class="errorMsgCode"
                                              style="float: right; font-weight: bold; font-size: 20pt; margin-left: 10px;">
                                            ${requestScope.msgcode}
                                        </span>
                                        <div class="button-box">
                                            <button type="submit" id="sub-btn"><span>会员注册</span></button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- login area end -->

<!-- Footer Area Start -->
<div class="footer-area">
    <div class="footer-container">
        <div class="footer-top">
            <div class="container">
                <div class="row">
                    <!-- Start single blog -->
                    <!-- End single blog -->
                    <!-- Start single blog -->
                    <div class="col-md-6 col-sm-6 col-lg-3 mb-md-30px mb-lm-30px" data-aos="fade-up"
                         data-aos-delay="400">
                        <div class="single-wedge">
                            <h4 class="footer-herading">信息</h4>
                            <div class="footer-links">
                                <div class="footer-row">
                                    <ul class="align-items-center">
                                        <li class="li"><a class="single-link" >关于我们</a></li>
                                        <li class="li"><a class="single-link" >交货信息</a></li>
                                        <li class="li"><a class="single-link" >隐私与政策</a></li>
                                        <li class="li"><a class="single-link" >条款和条件</a></li>
                                        <li class="li"><a class="single-link" >制造</a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- End single blog -->
                    <!-- Start single blog -->
                    <div class="col-md-6 col-lg-2 col-sm-6 mb-lm-30px" data-aos="fade-up" data-aos-delay="600">
                        <div class="single-wedge">
                            <h4 class="footer-herading">我的账号</h4>
                            <div class="footer-links">
                                <div class="footer-row">
                                    <ul class="align-items-center">
                                        <li class="li"><a class="single-link" >我的账号</a>
                                        </li>
                                        <li class="li"><a class="single-link" >我的购物车</a></li>
                                        <li class="li"><a class="single-link" >登录</a></li>
                                        <li class="li"><a class="single-link" >感兴趣的</a></li>
                                        <li class="li"><a class="single-link" >结账</a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- End single blog -->
                    <!-- Start single blog -->
                    <div class="col-md-6 col-lg-3" data-aos="fade-up" data-aos-delay="800">

                    </div>
                    <!-- End single blog -->
                </div>
            </div>
        </div>
        <div class="footer-bottom">
            <div class="container">
                <div class="row flex-sm-row-reverse">
                    <div class="col-md-6 text-right">
                        <div class="payment-link">
                            <img src="#" alt="">
                        </div>
                    </div>
                    <div class="col-md-6 text-left">
                        <p class="copy-text"></p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- Footer Area End -->
<script src="assets/js/vendor/vendor.min.js"></script>
<script src="assets/js/plugins/plugins.min.js"></script>
<!-- Main Js -->
<script src="assets/js/main.js"></script>
</body>
</html>